#include <stdio.h>
#include <unistd.h>
#include <sched.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#include <sys/ioctl.h>
#include <sys/syscall.h>
#include <sys/mman.h>
#include <string.h>

#define MY_DEV "/dev/mydev"
#define MEM_SIZE (4096)

int main(int argc, char *argv[])
{
	int fd;
	int *buf;

	fd = open(MY_DEV, O_RDWR);
	if (fd < 0) {
		printf("open %s failed, errno=%d\n", MY_DEV, fd);
		return -1;
	}

	buf = (int*)mmap(NULL, MEM_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
	if (!buf) {
		printf("my_mmap failed\n");
		goto exit;
	}

	memset(buf, 0, MEM_SIZE);

	munmap(buf, MEM_SIZE);

exit:
	close(fd);

	return 0;
}
